package com.vca.common.utils;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;

/**
 * 日志工具类
 *
 * @author chenbing
 * @date 2022/9/14   13:07
 */
public class Log {

    private static String TAG = "Log";

    private static final Logger logger = LoggerFactory.getLogger(TAG);

    /**
     * 日志级别
     */
    public static final String DEBUG = "DEBUG";
    public static final String ERROR = "ERROR";
    public static final String WARN = "WARN";
    public static final String VERBOSE = "VERBOSE";
    public static final String INFO = "INFO";

    //默认的时间格式
    public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");

    /**
     * modify date format
     *
     * @param dateFormatString
     */
    public static void setDateFormat(String dateFormatString) {
        dateFormat = new SimpleDateFormat(dateFormatString);
    }

    /**
     * @Description:按级别标签记录信息
     * @Author: chenBing
     * @Date: 2022/9/14
     */
    public static void logInfo(String msg, String level) {
        if (level.equals(DEBUG) || level.equals(ERROR) || level.equals(WARN)) {
            logger.error(dateFormat.format(System.currentTimeMillis()) + ": " + TAG + "." + level + ": " + msg);
        } else if (level.equals(VERBOSE) || level.equals(INFO)) {
            logger.info(dateFormat.format(System.currentTimeMillis()) + ": " + TAG + "." + level + ": " + msg);
        }
    }

    /**
     * @Description:debug级别日志
     * @Author: chenBing
     * @Date: 2022/9/14
     */
    public static void debug(String TAG, String msg) {
        Log.TAG = TAG;
        logInfo(msg, DEBUG);
    }

    /**
     * @Description:error级别日志
     * @Author: chenBing
     * @Date: 2022/9/14
     */
    public static void error(String TAG, String msg) {
        Log.TAG = TAG;
        logInfo(msg, ERROR);
    }

    /**
     * @Description:warn级别日志
     * @Author: chenBing
     * @Date: 2022/9/14
     */
    public static void warn(String TAG, String msg) {
        Log.TAG = TAG;
        logInfo(msg, WARN);
    }

    /**
     * @Description:verbose级别日志
     * @Author: chenBing
     * @Date: 2022/9/14
     */
    public static void verbose(String TAG, String msg) {
        Log.TAG = TAG;
        logInfo(msg, VERBOSE);
    }

    /**
     * @Description:info级别日志
     * @Author: chenBing
     * @Date: 2022/9/14
     */
    public static void info(String TAG, String msg) {
        Log.TAG = TAG;
        logInfo(msg, INFO);
    }
}
